#include "Zombie/ZombieBase.h"
int Zombie::zombie_id;

void Zombie::zombie_init() {

}// 变量初始化


// 精灵初始化  参数1 精灵图片名字  参数2 ： 二维坐标名字
void Zombie::sprite_init( const Vec2& position_) {
	sprite->setPosition(position_);
}

// 设置精灵的大小  参数：缩放倍数
void Zombie::set_scale(float val_) {
	sprite->setScale(val_);
} 

//获取二维坐标
Vec2 Zombie::get_position() const {
	return position; 
}

//获取二维坐标的X
double Zombie::get_x() {
	return sprite->getPositionX();
}


//获取二维坐标的Y
double Zombie::get_y() {
	return sprite->getPositionY();
}

//获取当前僵尸血量
int Zombie::get_blood() const {
	return blood; 
}

//获取当前僵尸的攻击间隔时间
int Zombie::get_attack_time() const {
	return attack_time; 
}

//获取攻击值
int Zombie::get_attack_num() const {
	return attack_num; 
}

//设置移动速度
double Zombie::get_move_rate() const {
	return move_rate; 
}

//virtual void attack_plant(Plant & plant_); //攻击植物 使植物掉血

// 创建 僵尸移动动画
void Zombie::init_zombie_move_animation() {

}

//创建 僵尸吃植物动画
void Zombie::init_zombie_eat_animation() {

}

//创建僵尸等待动画
void Zombie::init_zombie_wait_animation() {

}

//僵尸 死亡动画
void Zombie::init_zombie_die_animation() {
	
} 

//时间开销分析
//就是额外构造俩对象的开销,不用从内存读数据，和原有的代码差不多
bool Zombie::run_zombie_move_animation() {
	if (is_dead) return false ;
	if (sprite == nullptr || zombie_move_animate == nullptr) return false ;
	is_dead = false;
	is_eat = false;
	is_move = true;
	is_wait = false;
	sprite->stopAllActions();
	sprite->runAction(RepeatForever::create(
	Animate::create(Animation::createWithSpriteFrames(zombie_move, 1.0 / 10))));
	sprite->runAction(MoveTo::create(70.0f,Vec2(-100.0,get_y())));
	double _zombiesCurrentSpeed = -0.3;
	auto dirc = this->sprite->getPosition();
	Vec2 tempdelta = Vec2(_zombiesCurrentSpeed, 0);
	this->sprite->setPosition(dirc + tempdelta);
}

void Zombie::run_zombie_eat_animation() {
	this->is_dead = false;
	this->is_eat = true;
	this->is_move = false;
	this->is_wait = false;
	sprite->stopAllActions();
	sprite->runAction(RepeatForever::create(
		Animate::create(Animation::createWithSpriteFrames(zombie_eat, 1.0 / 4))));;
}

void Zombie::run_zombie_wait_animation() {
	if (is_dead) return;
	if (sprite == nullptr || zombie_move_animate == nullptr) return;
	is_dead = false;
	is_eat = false;
	is_move = false;
	is_wait = true;
	sprite->stopAllActions();
	sprite->runAction(RepeatForever::create(
		Animate::create(Animation::createWithSpriteFrames(zombie_eat, 1.0 / 5))));
}

void Zombie::run_zombie_die_animation() {
	//auto delayt = DelayTime::create(3);
	is_dead = true;
	is_eat = false;
	is_move = false;
	is_wait = false;
	sprite->stopAllActions();
	sprite->runAction(
		Animate::create(Animation::createWithSpriteFrames(zombie_die, 1.0 / 2)));
	sprite->runAction(Sequence::create(DelayTime::create(2.0f), Blink::create(2.0f, 5), RemoveSelf::create(),nullptr));
	//removeFromParent();
	//removeChild();
}
//判断状态
bool Zombie::judge_eat() const {
	return is_eat; 
}

bool Zombie::judge_dead() const {
	return is_dead; 
}

bool Zombie::judge_move() const { 
	return is_move; 
}

bool Zombie::judge_wait() const { 
	return is_wait; 
}


